<?php

namespace common\models\base;

use Yii;

/**
 * This is the model class for table "{{%credit_order}}".
 *
 * @property int $id
 * @property int $custom_id 合作机构订单号,同一笔业务，订单编号跟申请分期接口中的订单号一致。
 * @property string $custname 客户
 * @property string $idtype 证件类型
 * @property string $idno 证件编号
 * @property string $relation 关系最长20本人、配偶、反担保
 * @property int $bank_id 发起银行
 * @property int $guarantee_company_dot_site_id 发起担保公司
 * @property int $status 状态
 * @property string $serialize_data 数据 序列化
 * @property string $mobile
 * @property string $big_data_validate_detail_shift_number
 * @property string $big_data_validate_person_recognition_shift_number
 * @property string $big_data_validate_data
 *
 * @property BaiRongValidateForCreditOrder[] $baiRongValidateForCreditOrders
 * @property BaiRongValidateLog[] $baiRongValidateLogs
 * @property Bank $bank
 * @property Custom $custom
 * @property GuaranteeCompanyDotSite $guaranteeCompanyDotSite
 * @property CreditOrderLog[] $creditOrderLogs
 */
class CreditOrder extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%credit_order}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['custom_id', 'custname', 'idtype', 'idno', 'relation', 'bank_id', 'guarantee_company_dot_site_id', 'serialize_data'], 'required'],
            [['custom_id', 'bank_id', 'guarantee_company_dot_site_id', 'status'], 'integer'],
            [['serialize_data', 'big_data_validate_data'], 'string'],
            [['custname'], 'string', 'max' => 100],
            [['idtype'], 'string', 'max' => 10],
            [['idno'], 'string', 'max' => 19],
            [['relation'], 'string', 'max' => 20],
            [['mobile'], 'string', 'max' => 11],
            [['big_data_validate_detail_shift_number', 'big_data_validate_person_recognition_shift_number'], 'string', 'max' => 50],
            [['custom_id', 'relation', 'idtype', 'idno'], 'unique', 'targetAttribute' => ['custom_id', 'relation', 'idtype', 'idno']],
            [['bank_id'], 'exist', 'skipOnError' => true, 'targetClass' => Bank::className(), 'targetAttribute' => ['bank_id' => 'id']],
            [['custom_id'], 'exist', 'skipOnError' => true, 'targetClass' => Custom::className(), 'targetAttribute' => ['custom_id' => 'id']],
            [['guarantee_company_dot_site_id'], 'exist', 'skipOnError' => true, 'targetClass' => GuaranteeCompanyDotSite::className(), 'targetAttribute' => ['guarantee_company_dot_site_id' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'custom_id' => Yii::t('app', '合作机构订单号,同一笔业务，订单编号跟申请分期接口中的订单号一致。'),
            'custname' => Yii::t('app', '客户'),
            'idtype' => Yii::t('app', '证件类型'),
            'idno' => Yii::t('app', '证件编号'),
            'relation' => Yii::t('app', '关系最长20本人、配偶、反担保'),
            'bank_id' => Yii::t('app', '发起银行'),
            'guarantee_company_dot_site_id' => Yii::t('app', '发起担保公司'),
            'status' => Yii::t('app', '状态'),
            'serialize_data' => Yii::t('app', '数据 序列化'),
            'mobile' => Yii::t('app', 'Mobile'),
            'big_data_validate_detail_shift_number' => Yii::t('app', 'Big Data Validate Detail Shift Number'),
            'big_data_validate_person_recognition_shift_number' => Yii::t('app', 'Big Data Validate Person Recognition Shift Number'),
            'big_data_validate_data' => Yii::t('app', 'Big Data Validate Data'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getBaiRongValidateForCreditOrders()
    {
        return $this->hasMany(BaiRongValidateForCreditOrder::className(), ['credit_order_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getBaiRongValidateLogs()
    {
        return $this->hasMany(BaiRongValidateLog::className(), ['id' => 'bai_rong_validate_log_id'])->viaTable('{{%bai_rong_validate_for_credit_order}}', ['credit_order_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getBank()
    {
        return $this->hasOne(Bank::className(), ['id' => 'bank_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCustom()
    {
        return $this->hasOne(Custom::className(), ['id' => 'custom_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getGuaranteeCompanyDotSite()
    {
        return $this->hasOne(GuaranteeCompanyDotSite::className(), ['id' => 'guarantee_company_dot_site_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCreditOrderLogs()
    {
        return $this->hasMany(CreditOrderLog::className(), ['credit_order_id' => 'id']);
    }
}
